﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;
using Foothill.Model;
using Foothill.Common;

namespace Foothill.Model.Test
{
    [TestFixture]
    public class AddCityFilterItemTest
    {
        private const int VancouverCityId = 1;
        private const int BurnabyCityId = 2;
        private const int RichmondCityId = 3;
        private const int LangleyCityId = 4;

        private readonly IList<int> _citiesIdList;

        public AddCityFilterItemTest()
        {
            _citiesIdList = new List<int> { VancouverCityId, BurnabyCityId, LangleyCityId };
        }

        [Test]
        public void AddOneCityToEmptyList()
        {
            ForSaleAdAdvancedSearchParameter underTest = new ForSaleAdAdvancedSearchParameter(_citiesIdList);
            AdCategorySelectItem cityItem = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = VancouverCityId };
            underTest.AddFilterItem(cityItem);

            IList<int> expected = new List<int> { VancouverCityId };
            CollectionAssert.AreEqual(expected, underTest.LocationIdList);
        }

        [Test]
        public void AddAllCitiesToList_ShouldSetAllCitySelectedToTrue()
        {
            ForSaleAdAdvancedSearchParameter underTest = new ForSaleAdAdvancedSearchParameter(_citiesIdList);

            AdCategorySelectItem cityItem1 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = VancouverCityId };
            AdCategorySelectItem cityItem2 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = BurnabyCityId };
            AdCategorySelectItem cityItem3 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = RichmondCityId };
            AdCategorySelectItem cityItem4 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = LangleyCityId };

            underTest.AddFilterItem(cityItem1);
            underTest.AddFilterItem(cityItem2);
            underTest.AddFilterItem(cityItem3);
            underTest.AddFilterItem(cityItem4);

            Assert.IsTrue(underTest.AllLocationSelected);
        }

        [Test]
        public void AddOneCity_AfterAddingAllFourCities_ShouldHaveOnlyOneCityIdInTheList()
        {
            ForSaleAdAdvancedSearchParameter underTest = new ForSaleAdAdvancedSearchParameter(_citiesIdList);

            AdCategorySelectItem cityItem1 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = VancouverCityId };
            AdCategorySelectItem cityItem2 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = BurnabyCityId };
            AdCategorySelectItem cityItem3 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = RichmondCityId };
            AdCategorySelectItem cityItem4 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = LangleyCityId };

            underTest.AddFilterItem(cityItem1);
            underTest.AddFilterItem(cityItem2);
            underTest.AddFilterItem(cityItem3);
            underTest.AddFilterItem(cityItem4);

            underTest.AddFilterItem(cityItem1);

            IList<int> expected = new List<int> { VancouverCityId };
            CollectionAssert.AreEqual(expected, underTest.LocationIdList);
        }

        [Test]
        public void RemoveTheOnlyCity_ShouldSetAllCitySelectedToTrue()
        {
            ForSaleAdAdvancedSearchParameter underTest = new ForSaleAdAdvancedSearchParameter(_citiesIdList);

            AdCategorySelectItem cityItem1 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Add, SelectedIdValue = VancouverCityId };
            underTest.AddFilterItem(cityItem1);

            AdCategorySelectItem removeCityItem1 = new AdCategorySelectItem() { Category = AdListCategory.City, Action = SelectItemAction.Remove, SelectedIdValue = VancouverCityId };
            underTest.AddFilterItem(removeCityItem1);
            Assert.IsTrue(underTest.AllLocationSelected);
        }
    }
}
